package com.scs.application.modules.msg.sender;

import com.scs.application.core.exception.BusinessException;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.modules.msg.model.SmsMessage;
import com.scs.application.modules.msg.service.SmsTemplateService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 */
public abstract class SmsMessageSender<T extends SmsMessage> extends MessageSender<T> {

    @Autowired(required = false)
    protected SmsTemplateService smsTemplateService;

    @Override
    protected void beforeSend(T msg) {
        super.beforeSend(msg);
        if(StringUtils.isBlank(msg.getMobiles())){
            throw new BusinessException("短信发送失败：手机号不能为空");
        }
        if(StringUtils.isNoneBlank(msg.getTplKey()) && smsTemplateService == null){
            throw new BusinessException("短信发送失败：短信模板服务实例不能为空");
        }
    }


}
